#ifndef SPRITE_H
#define SPRITE_H
#include "Entity.h"
#include <QVector2D>
#include "Animation.h"
#include <QMap>
class Sprite:public Entity
{
public:
    Sprite();
    Sprite(int x,int y,const QString& filename);
    ~Sprite();
    void update()override;
    void draw(QPainter*painter)override;

    void setPos(int x,int y);
    void moveBy(int dx,int dy);
    inline int width()const{if(!pixmap.isNull()){return pixmap.width();}return 0;};
    inline int height()const{if(!pixmap.isNull()){return pixmap.height();}return 0;};

    Animation* addAnimation(const QString&tag,Animation * anima);
    void runAnimation(const QString&tag,bool autoDel=false);

public:
    QVector2D position;//坐标
    QPixmap pixmap;    //精灵图

    QVector2D velocity;
    int speed=3;

    QRect collider;   //碰撞器
    void setCollider(const QRect &newCollider);


private:
    QMap<QString,Animation*> animas;
    Animation * currentAnima=nullptr;
    bool autoDel=false;
};

#endif // SPRITE_H
